package cn.tedu.luckydrawuser.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.List;

@RestController
public class TestController {

    @GetMapping("/test")
    public Mono<String> test(){
        //Mono.just()是Reactor中创建的的包含单个元素的一个对象
        return Mono.just("Hello, WebFlux");
    }

    @GetMapping("/test-jusOrEmpty")
    public Mono<String> justOrEmpty(){
        return Mono.justOrEmpty(null);
    }

    @GetMapping("/test-fluxJust")
    public Flux<String> fluxJust(){
        return Flux.just("A老师","B老师","C老师");
    }

    @GetMapping("/test-fromIterable")
    public Flux<String> fromIterable(){
        List<String> list = Arrays.asList("A老师", "B老师", "C老师");
        return Flux.fromIterable(list);
    }

    @GetMapping("/test-empty")
    public Flux<String> fluxEmpty(){
        return Flux.empty();
    }

    @GetMapping("/test-range")
    public Flux<Integer> testRange(){
        return Flux.range(3, 5);
    }
}
